using AntDesign;
using Microsoft.AspNetCore.Components;
using StudentVideo.Client.Routers;
using StudentVideo.Client.Services;
using StudentVideo.Shared.Models;
using StudentVideo.Shared.Dtos.Student;

namespace StudentVideo.Client.Pages.Student;

public partial class List: ComponentBase {
   [Inject] public required StudentRouter _studentRouter { get; set; }
   [Inject] public required PageLoadingService _pageLoading { get; set; }

   private Table<StudentFindResultItem> _table { get; set; } = null!;

   private StudentFindRequest queryForm = new() {
      Name = null,
      Major = null,
      CreateTimeBetween = null,
      EnrollmentDateBetween = null,
      SchoolYear = null,
      Sex = null,
      Semester = null,
      Page = new() {
         PageCurrent = 1,
         PageSize = 20
      }
   };

   private List<StudentFindResultItem>? StudentList { get; set; }

   protected override async Task OnAfterRenderAsync(bool firstRender) {
      await base.OnAfterRenderAsync(firstRender);

      if (!firstRender)
         return;

      await SearchList(queryForm);

      _pageLoading.SetStatus(false);

      StateHasChanged();
   }

   private async Task SearchList(StudentFindRequest form) {
      HttpResult<StudentFindResult> result = await _studentRouter.Find(form);

      StudentList = result.Data?.List;
   }
}
